import Vue from 'vue'
import Router from 'vue-router'

// 初始路由集
const home = () => import('../page/home'),
    apply = () => import('../page/appointment'),
    applyPremise = () => import('../page/apply-premise'),
    sweepCodeCheck = () => import('../page/sweep-code-check'),
    accompany = () => import('../page/accompany'),
    code = () => import('../page/health-code'),
    login = () => import('../page/login'),
    scanCodeInOut = () => import('../page/scan-code-in-out'),
    registration = () => import('../page/registration'),
    cartReg = () => import('../page/cart-reg'),
    registrationInfo = () => import('../page/registration-info'),
    scanCheck = () => import('../page/scan-check'),
    punchCard = () => import('../page/punch-card'),
    uploadCardId = () => import('../page/upload-card-id'),
    lookCardId = () => import('../page/look-card-id'),
    outsideCarRegister = () => import('../page/outside-car-register'),
    department = () => import('../components/department'),
    constantRouterMap = [
        {
            path: '/',
            name: 'index',
            redirect: '/home'
        },
        {
            path: '/home',
            name: 'home',
            component: home,
            meta: {
                title: '首页',
                keepAlive: false
            }
        },
        {
            path: '/login',
            name: 'login',
            component: login,
            meta: {
                title: '登录页',
                keepAlive: false
            }
        },
        {
            path: '/scanCodeInOut',
            name: 'scanCodeInOut',
            component: scanCodeInOut,
            meta: {
                title: '外来车辆登记',
                keepAlive: false
            }
        },
        {
            path: '/cartReg',
            name: 'cartReg',
            component: cartReg,
            meta: {
                title: '外来车辆登记结果',
                keepAlive: false
            }
        },
        {
            path: '/registration',
            name: 'registration',
            component: registration,
            meta: {
                title: '扫码登记',
                keepAlive: false
            },
            children: []
        },
        {
            path: '/registrationInfo',
            name: 'registrationInfo',
            component: registrationInfo,
            meta: {
                title: '登记信息',
                keepAlive: false
            }
        },
        {
            path: '/apply-premise',
            name: 'applyPremise',
            component: applyPremise,
            meta: {
                title: '防控须知',
                keepAlive: false
            }
        },
        {
            path: '/apply',
            name: 'apply',
            component: apply,
            meta: {
                title: '预约申请',
                keepAlive: false
            },
            children: [
                {
                    path: 'uploadCardId',
                    name: 'uploadCardId',
                    component: uploadCardId,
                    meta: {
                        title: '上传身份证照片',
                        keepAlive: false
                    }
                },
                {
                    path: 'department',
                    name: 'applyDepartment',
                    component: department,
                    meta: {
                        title: '科室选择',
                        keepAlive: false
                    }
                }
            ]
        },
        {
            path: '/sweepCodeCheck',
            name: 'sweepCodeCheck',
            component: sweepCodeCheck,
            meta: {
                title: '扫码检查',
                keepAlive: false
            },
            children: [
                {
                    path: 'accompany',
                    name: 'accompany',
                    component: accompany,
                    meta: {
                        title: '陪同',
                        keepAlive: false
                    }
                },
                {
                    path: 'lookCardId',
                    name: 'lookCardId',
                    component: lookCardId,
                    meta: {
                        title: '查看身份证照片',
                        keepAlive: false
                    }
                }
            ]
        },
        {
            path: '/code',
            name: 'code',
            component: code,
            meta: {
                title: '查看健康码',
                keepAlive: false
            }
        },
        {
            path: '/scanCheck',
            name: 'scanCheck',
            component: scanCheck,
            meta: {
                title: '扫码登记',
                keepAlive: false
            }
        },
        {
            path: '/punchCard',
            name: 'punchCard',
            component: punchCard,
            meta: {
                title: '健康打卡',
                keepAlive: false
            }
        },
        {
            path: '/outsideCarRegister',
            name: 'outsideCarRegister',
            component: outsideCarRegister,
            meta: {
                title: '外来车辆登记',
                keepAlive: false
            },
            children: [
                {
                    path: 'department',
                    name: 'outsideDepartment',
                    component: department,
                    meta: {
                        title: '科室选择',
                        keepAlive: false
                    }
                }
            ]
        },
        {
            path: '/department',
            name: 'deDepartment',
            component: department,
            meta: {
                title: '科室选择',
                keepAlive: false
            }
        }
    ]

let router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router
